const path = require('path');
let merge = require('webpack-merge')
let base = require('./webpack.base')
let HtmlWebpackPlugin = require('html-webpack-plugin')
let VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
let externals = require('webpack-node-externals')

module.exports = merge(base, {
  target: 'node', // node环境
  entry: {server: path.resolve(__dirname, '../src/server-entry.js')},
  output: {
    libraryTarget: 'commonjs2'
  },
  externals:[externals()], // 第三方模块不需要打包
  plugins: [
    new VueSSRServerPlugin(),
    new HtmlWebpackPlugin({ // 服务端模板
      // 现在的问题是 默认会把服务的js引入这个html   但是其实希望的是把client的js放进去 
      filename: 'index.ssr.html',
      template: path.resolve(__dirname, '../public/index.ssr.html'),
      excludeChunks: ['server'] // 把这个文件排除
    }),
  ]
})